import { _decorator, Component, Node, Prefab, resources } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('ResManager')
export class ResManager extends Component {

    private static _instance: ResManager;
    public static get instance(): ResManager {
        if (!this._instance) {
            this._instance = new ResManager();
        }
        return this._instance;
    }

    public loadRes(url: string, callBack: Function) {
        resources.load(url, (err, res: any) => {
            if (err) {
                console.error(err);
                callBack && callBack(res, err);
                return;
            }
            callBack && callBack(res, null);

        });
    }
    public loadPrefab(url: string): Promise<any> {
        return new Promise((resolve, reject) => {
            this.loadRes(url, (res: any, err: Error) => {
                if (err) {
                    reject && reject();
                } else {
                    resolve && resolve(res as Prefab);
                }
            })
        })
    }
}


